/**
 * @author: 子龙
 */
package com.fzl.lotterysystem.service.activitystatus.operator;

import com.fzl.lotterysystem.dao.dataobject.ActivityPrizeDO;
import com.fzl.lotterysystem.dao.mapper.ActivityPrizeMapper;
import com.fzl.lotterysystem.service.ActivityService;
import com.fzl.lotterysystem.service.DTO.ConvertActivityStatusDTO;
import com.fzl.lotterysystem.service.enums.ActivityPrizeStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PrizeOperator extends AbstractActivityOperator{

    @Autowired
    private ActivityPrizeMapper activityPrizeMapper;

    @Override
    public Integer sequence() {
        return 1;
    }

    @Override
    public Boolean needConvert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        Long prizeId = convertActivityStatusDTO.getPrizeId();
        Long activityId = convertActivityStatusDTO.getActivityId();
        ActivityPrizeStatusEnum statusEnum=convertActivityStatusDTO.getTargetPrizeStatus();
        if(activityId==null||prizeId==null || statusEnum==null){
            return false;
        }

        ActivityPrizeDO activityPrizeDO= activityPrizeMapper.selectByAPId(activityId,prizeId);

        if(activityPrizeDO==null){
            return false;
        }

        //当前活动状态与传入的状态是否一致，一致就不处理
        if (activityPrizeDO.getPrizeTiers().equalsIgnoreCase(statusEnum.name())){
            return false;
        }
        return true;
    }

    @Override
    public Boolean convert(ConvertActivityStatusDTO convertActivityStatusDTO) {
        Long prizeId = convertActivityStatusDTO.getPrizeId();
        Long activityId = convertActivityStatusDTO.getActivityId();
        ActivityPrizeStatusEnum statusEnum=convertActivityStatusDTO.getTargetPrizeStatus();
        try {
            activityPrizeMapper.updateStatus(activityId,prizeId,statusEnum.name());
            return true;
        }catch (Exception e){
            return false;
        }

    }
}